package com.genntii.examManager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.genntii.examManager.domain.entity.Exam;
import com.genntii.examManager.domain.entity.Practice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

@Mapper
public interface PracticeMapper extends BaseMapper<Practice> {

    @Select("select count(*) from practice where course_id = #{courseId}")
    Integer getPracticeCount(@Param("courseId") Long courseId);

    ArrayList<Long> getPracticeCountBatch(ArrayList<Long> courseIds);

    @Select("select * " +
            "from practice " +
            "where course_id = #{courseId} "+
            "order by update_time DESC " +
            "limit #{pageNum},#{pageSize}")
    ArrayList<Practice> getPracticeList(@Param("pageNum") Integer pageNum,
                                        @Param("pageSize") Integer pageSize,
                                        @Param("courseId") Long courseId);

    @Select("select * from practice ")
    long getPracticeTotal();

    ArrayList<Practice> getPracticeBatch(ArrayList<Long> examIds);

    @Select("select * from practice where course_id = #{courseId}")
    ArrayList<Practice> getPracticeAllListByCourse(@Param("courseId") Long courseId);

    @Update("update practice set status = #{status} where id = #{practiceId}")
    void setStatus(@Param("status") Byte status,
                   @Param("practiceId") Long practiceId);
}
